
<?php


class checksDate {
  
function dataAtual(){
ini_set('date.timezone','America/SAO_PAULO');
return date("Y-m-d H:i:s");
}

function dataAtualSimples(){
ini_set('date.timezone','America/SAO_PAULO');
return date("Y-m-d");
}



public function DiferencaData($datein,$dateout){ // criamos a função 
$data = $datein;//data inicial
$diai = substr("$data", 8, 2); // dia
$mesi = substr("$data", 5, 2); // mes
$anoi = substr("$data", 0, 4); // ano
$horai = substr("$data",11, 2);//hora
$mini = substr("$data",14,2);//minutos
$segi = substr("$data",17,2);//segundos

$data = $dateout;//data inicial
$diaf = substr("$data", 8, 2); // dia
$mesf = substr("$data", 5, 2); // mes
$anof = substr("$data", 0, 4); // ano
$horaf = substr("$data",11, 2);//hora
$minf = substr("$data",14,2);//minutos
$segf = substr("$data",17,2);//segundos

$dini = mktime($horai,$mini,$segi,$mesi,$diai,$anoi);
$dinf = mktime($horaf,$minf,$segf,$mesf,$diaf,$anof);
$total = (int)(($dinf - $dini)/3600);
return $total;

}




public function convertsDate($date){
            if(strstr($date,'/')){
                $date = explode('/',$date);
                $parsedData = $date[2]."-".$date[1]."-".$date[0];
                return $parsedData;
            }

            if(strstr($date,'-')){
                $date = explode('-',$date);
                $parsedData = $date[2]."/".$date[1]."/".$date[0];
                return $parsedData;
            }

}




public function convertsDatehora( $date )

{
 if(strstr($date,'/')){
                $dateAux = explode(' ',$date);
                 $date1=$dateAux[0];
                 $hora=$dateAux[1];
                return $this->convertsDate($date1)." $hora";
                
            }
  if(strstr($date,'-')){
                $dateAux = explode(' ',$date);
                 $date1=$dateAux[0];
                 $hora=$dateAux[1];
                return $this->convertsDate($date1)." $hora";
            }
}

}

?>
